package com.apollo.android.um.utils;

import com.apollo.android.um.constants.Constants;
import com.apollo.android.utils.Helper;
import com.apollo.android.utils.PreferencesHelper;

public class AppCache {
    private AppCache() {
    }

    public static void saveDeviceToken(String deviceToken) {
        if (Helper.isNotEmpty(deviceToken)) {
            PreferencesHelper.getInstance().putString(Constants.KEY_DEVICE_TOKEN, deviceToken);
            saveDeviceTokenErrorMessage(null);
        } else {
            PreferencesHelper.getInstance().remove(Constants.KEY_DEVICE_TOKEN);
        }
    }

    public static String getDeviceToken() {
        return PreferencesHelper.getInstance().getString(Constants.KEY_DEVICE_TOKEN);
    }

    public static boolean haveDeviceTokenError() {
        final String deviceToken = getDeviceToken();
        if (Helper.isEmpty(deviceToken)) {
            return true;
        }
        return false;
    }

    public static void saveDeviceTokenErrorMessage(String message) {
        if (Helper.isNotEmpty(message)) {
            PreferencesHelper.getInstance().putString(Constants.KEY_DEVICE_TOKEN_MESSAGE, message);
        } else {
            PreferencesHelper.getInstance().remove(Constants.KEY_DEVICE_TOKEN_MESSAGE);
        }
    }

    public static String getDeviceTokenMessage() {
        return PreferencesHelper.getInstance().getString(Constants.KEY_DEVICE_TOKEN_MESSAGE);
    }
}
